function doViewCard(id)
{
	ajax.send('?m=contacts&a=view&suppressHeaders=1&contact_id='+id, '',
		function (r) {
			var cd = Control('idContactDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd).show();
		}
	);
}

function doGetCard(id)
{
	go('?m=contacts&a=vcardexport&suppressHeaders=true&contact_id='+id);
}

function doEditStatus(id, extra)
{
	ajax.send('?m=masterdata&a=mdstatus_edit&suppressHeaders=1&status_id='+id+''+extra, '',
		function (r) {
			var cd = Control('idStatusDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd, 1).show();
			eval($('validation_rules').innerHTML);
			/*
			Calendar.setup(
				{
					inputField  : 'idBirthday',
					ifFormat    : '%Y-%m-%d',
					displayArea : 'idBirthdayD',
					daFormat    : SHDATEFORMAT,
					button      : 'idBirthdayB'
				}
			);
			*/

		}
	);
}

function doCloseStatus()
{
	Control('idDeptSelector').destroy();
	Dialog('idStatusDialog').hide();
}

function doSwitchTab(tab)
{
	if (tab.className == 'here') return;
	var c, i, r = tab.parentNode;
	for (i = 0; i < r.cells.length; i++) {
		if (r.cells[i].className == 'here') {
			c = r.cells[i];
			c.className = 'tab';
			break;
		}
	}
	tab.className = 'here';
	Control('id' + c.innerHTML).hide();
	Control('id' + tab.innerHTML).show();
}

function doChangeCompany()
{
	$('idDeptName').value = '';
	$('idDeptId').value = 0;
}

function doSelectDepartment(id)
{
	$('idDeptId').value = id;
	$('idDeptName').value = unescape($('idDept['+id+']').getAttribute('value'));
	Control('idDeptSelector').destroy();
}

function doShowDeptSelector()
{
	var c = $('idContactCompany');
	var id = c.options[c.selectedIndex].value;
	ajax.send('index.php?m=public&a=viewinfo&suppressHeaders=1&type=DepartmentList&id='+id, '',
		function(r) {
			var d = Control('idDeptSelector').create('div', 'topper', 'hidden');
			var error = r.indexOf('idDeptList') < 0;
			if (!error) {
				r = r.replace(/\n|\r/g,'');
				r = r.replace(/\<tr\>.*?\<\/tr\>/i,'');
				r = r.replace(/width="250px"/i, 'width="260px"');
				r = r.replace(/cellpadding="4"/i, 'cellpadding="0"');
			}
			d.innerHTML = r;
			Control(d).show();
			if (!error) initTree($('idDeptTree'));
			$('idContactDialog').onclick = function() {
				Control('idDeptSelector').destroy();
				this.onclick = undefined;
			}
			if (error) {
				Control(d).center();
			}
			else {
				var p = Control('idDeptName').position();
				Control(d).move(p.x + 3, p.y + 22);
			}
		}
	);
}
// trangdt
/*
*Currency
*/
function doViewCurrency(id)
{
	ajax.send('?m=masterdata&a=mdcurrency_view&suppressHeaders=1&currency_id='+id, '',
		function (r) {
			var cd = Control('idCurrencyDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd).show();
		}
	);
}

function doEditCurrency(id, extra)
{
	ajax.send('?m=masterdata&a=mdcurrency_edit&suppressHeaders=1&currency_id='+id+''+extra, '',
		function (r) {
			var cd = Control('idCurrencyDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			eval($('validation_rules').innerHTML);
			Dialog(cd, 1).show();
		}
	);
}

function doCloseCurrency()
{
	Dialog('idCurrencyDialog').hide();
}
/*
 *Unit
 */
function doViewUnit(id)
{
	ajax.send('?m=masterdata&a=mdunit_view&suppressHeaders=1&unit_id='+id, '',
		function (r) {
			var cd = Control('idUnitDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd).show();
		}
	);
}

function doEditUnit(id, extra)
{
	ajax.send('?m=masterdata&a=mdunit_edit&suppressHeaders=1&unit_id='+id+''+extra, '',
		function (r) {
			var cd = Control('idUnitDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd, 1).show();
			eval($('validation_rules').innerHTML);
		}
	);
}

function doCloseUnit()
{
	Dialog('idUnitDialog').hide();
}

// trangdt

/*
 * Type
 */
function doViewType(id)
{
	ajax.send('?m=masterdata&a=mdtype_view&suppressHeaders=1&type_id='+id, '',
		function (r) {
			var cd = Control('idTypeDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd).show();
		}
	);
}

function doEditType(id, extra)
{
	ajax.send('?m=masterdata&a=mdtype_edit&suppressHeaders=1&type_id='+id+''+extra, '',
		function (r) {
			var cd = Control('idTypeDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd, 1).show();
			eval($('validation_rules').innerHTML);
		}
	);
}

function doCloseType()
{
	Control('idDeptSelector').destroy();
	Dialog('idTypeDialog').hide();
}
/*
* Job Title
*/
function doViewJobTitle(id)
{
	ajax.send('?m=masterdata&a=mdjobtitle_view&suppressHeaders=1&jobtitle_id='+id, '',
		function (r) {
			var cd = Control('idJobTitleDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd).show();
		}
	);
}

function doEditJobTitle(id, extra)
{
	ajax.send('?m=masterdata&a=mdjobtitle_edit&suppressHeaders=1&jobtitle_id='+id+''+extra, '',
		function (r) {
			var cd = Control('idJobTitleDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd, 1).show();
			eval($('validation_rules').innerHTML);
		}
	);
}

function doCloseJobTitle()
{
	Dialog('idJobTitleDialog').hide();
}
/*
 *Division
 */
function doViewDivision(id)
{
	ajax.send('?m=masterdata&a=mddivision_view&suppressHeaders=1&div_id='+id, '',
		function (r) {
			var cd = Control('idDivisionDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd).show();
		}
	);
}

function doEditDivision(id, extra)
{
	ajax.send('?m=masterdata&a=mddivision_edit&suppressHeaders=1&div_id='+id+''+extra, '',
		function (r) {
			var cd = Control('idDivisionDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd, 1).show();
			eval($('validation_rules').innerHTML);
		}
	);
}

function doCloseDivision()
{
	Dialog('idDivisionDialog').hide();
}
/**
 *Cost Center
**/
function doViewCostCenter(id)
{
	ajax.send('?m=masterdata&a=mdcostcenter_view&suppressHeaders=1&cc_id='+id, '',
		function (r) {
			var cd = Control('idCostCenterDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd).show();
		}
	);
}

function doEditCostCenter(id, extra)
{
	ajax.send('?m=masterdata&a=mdcostcenter_edit&suppressHeaders=1&cc_id='+id+''+extra, '',
		function (r) {
			var cd = Control('idCostCenterDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd, 1).show();
			eval($('validation_rules').innerHTML);
		}
	);
}

function doCloseCostCenter()
{
	Dialog('idCostCenterDialog').hide();
}
/*
function doViewCls(id)
{
	ajax.send('?m=masterdata&u=classification&a=view&suppressHeaders=1&cls_id='+id, '',
		function (r) {
			var cd = Control('idClsDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd).show();
		}
	);
}

function doEditCls(id, extra)
{
	ajax.send('?m=masterdata&a=edit&u=classification&suppressHeaders=1&cls_id='+id+''+extra, '',
		function (r) {
			var cd = Control('idClsDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd, doCloseCls).show();
			eval($('validation_rules').innerHTML);
		}
	);
}

function doCloseCls()
{
	Dialog('idClsDialog').hide();
}
*/

function doChangeType(typeCbx) {
	var itemsPattern = /^Itemtype/i;
	if (itemsPattern.test(typeCbx.value)) {
		$('idItemScreen').style.display = 'block';
	}
	else {
		$('idItemScreen').style.display = 'none';
	}
}

function doDelete(id, name)	{
	if (confirm( "Do you want to delete "+ name)) {
		$('del_cc_id').value = id;
		f = $('MdFormDelete');
		f.del.value = id;
		f.submit();
	}
}